'use strict';
const Controller = require('egg').Controller;
const { setMenuActive } = require('./utils');

class HomeController extends Controller {
  async index() {
    const ctx = this.ctx;
    const targetURLNode = ctx.targetURLNode;
    const banner = await ctx.service.cms.getBanner({
      page: 1,
    });
    await ctx.service.cms.getMenu();
    // 获取首页快捷导航
    const data = {
      menu: setMenuActive(ctx.app.menus, targetURLNode.urlNode.label),
      banner,
    };
    await this.ctx.render('index.njk', data);
  }
}

module.exports = HomeController;
